package com.jt.controller;

import com.jt.pojo.User;
import com.jt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RefreshScope
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 基于用户名查询用户信息，后续在sso-auth服务中会对这个方法进行远程调用
     * @param username
     * @return
     */
    @GetMapping("/login/{username}")
    public User doSelectUserByUserName(@PathVariable("username") String username){
       return userService.selectUserByUserName(username);
    }

    /**
     * 基于用户id查询权限，后续会在sso-auth服务中会对这个方法进行远程调用
     * @param userId
     * @return
     */
    @GetMapping("/permission/{userId}")
    public List<String> doSelectUserPermissions(@PathVariable("userId") Long userId){
        return userService.selectUserPermissions(userId);
    }
}
